package com.yoomiito.app.present;

import com.yoomiito.app.MainActivity;
import com.yoomiito.app.base.AppConfig;
import com.yoomiito.app.base.BaseActPresenter;
import com.yoomiito.app.model.LiveUserInfo;
import com.yoomiito.app.model.bean.VersionInfo;
import com.yoomiito.app.net.YmApi;
import com.yoomiito.app.utils.NetworkUtils;

import cn.droidlover.xdroidmvp.net.ApiException;
import cn.droidlover.xdroidmvp.net.ApiSubscriber;
import cn.droidlover.xdroidmvp.net.XApi;

public class MainPresenter extends BaseActPresenter<MainActivity> {


    public MainPresenter(AppConfig appConfig) {
        super(appConfig);
    }

    public void getNewVersion(){
        YmApi.getYmService()
                .newVersion(1)
                .compose(getV().bindToLifecycle())
                .compose(XApi.getApiTransformerData())
                .compose(XApi.getScheduler())
                .subscribe(new ApiSubscriber<VersionInfo>(handleException()) {
                    @Override
                    public void onSuccess(VersionInfo versionInfo) {
                        if (hasV()){
                            getV().setVersionInfo(versionInfo);
                        }

                    }

                    @Override
                    public void onFail(ApiException error) {
                        if (hasV()){
                            getV().setVersionInfo(null);
                        }

                    }
                });
    }

    public void getLiveInfo(){
        YmApi.getYmService()
                .getLiveUser()
                .compose(getV().bindToLifecycle())
                .compose(XApi.getApiTransformerData())
                .compose(XApi.getScheduler())
                .subscribe(new ApiSubscriber<LiveUserInfo>(handleException()) {
                    @Override
                    public void onSuccess(LiveUserInfo liveUserInfo) {
                        if (hasV()){
                            getV().setLiveUserInfo(liveUserInfo);
                        }
                    }

                    @Override
                    public void onFail(ApiException error) {

                    }
                });
    }

}
